package com.xnyzc.lhy.order.controller.capi.sidebar;

import com.xnyzc.lhy.common.component.config.security.TokenUser;
import com.xnyzc.lhy.common.constant.CommonConstant;
import com.xnyzc.lhy.common.constant.SecurityConstant;
import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.entity.user.OaCUser;
import com.xnyzc.lhy.order.service.sidebar.SidebarService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.security.RolesAllowed;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 侧边栏信息 前端控制器
 * </p>
 *
 * @author lhy@xnyzc.com
 * @since 2019-07-17
 */
@RestController
@RequestMapping("/capi/sidebar")
public class SidebarController {

    @Autowired
    private SidebarService sidebarService;

    @ApiOperation("获取侧边栏信息")
    @GetMapping("/getSidebarInfo")
    public Rv getSidebarInfo() {
        Long userId = TokenUtil.getTokenUserId();
        return sidebarService.getSidebarInfo(userId);
    }

    @ApiOperation("获取用户信息")
    @GetMapping("/getSupport")
    public Rv getSupport(HttpServletRequest httpServletRequest) {
        String authorization = httpServletRequest.getHeader(CommonConstant.REQ_HEADER);
        String token ="";
        if(StringUtils.isNotEmpty(authorization)){
            token = StringUtils.substringAfter(authorization, CommonConstant.TOKEN_SPLIT);
        }
        return sidebarService.getSupport(token);
    }

}
